class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        int len = tokens.size();
        if(len==0) return 0;

        stack <int> stk;
        int a,b;
        int result;
        for(string str:tokens)
        {
            //cout<<str[0]<<"*****"<<endl;
            int temp = 0;
            switch (str[str.size()-1])
            {
                case '+':
                {
                    //cout<<"++ "<<endl;
                    a = stk.top();
                    stk.pop();
                    b = stk.top();
                    stk.pop();
                    result = a + b;
                    stk.push(result);
                    //cout<<result<<" "<<a<<" "<<b<<endl;
                    break;
                }
                case '-':
                {
                    //cout<<"-- "<<endl;
                    a = stk.top();
                    stk.pop();
                    b = stk.top();
                    stk.pop();
                    result = b - a;
                    stk.push(result);
                    //cout<<result<<" "<<a<<" "<<b<<endl;
                    break;
                }
                case '*':
                {
                    //cout<<"** "<<endl;
                    a = stk.top();
                    stk.pop();
                    b = stk.top();
                    stk.pop();
                    result = a * b;
                    stk.push(result);
                    //cout<<result<<endl;
                    break;
                }
                case '/':
                {
                    //cout<<"// "<<endl;
                    a = stk.top();
                    stk.pop();
                    b = stk.top();
                    stk.pop();
                    result = b / a;
                    stk.push(result);
                    //cout<<result<<" "<<a<<" "<<b<<endl;
                    break;
                }
                default:
                {
                    bool flag = false;
                    for(char ch:str)
                    { 
                        if(ch=='-')
                        {
                            flag = true;
                            continue;
                        }
                        temp = temp*10+(ch-'0');
                    }
                    //cout<<"^^^^"<<temp;
                    if(flag)
                        stk.push(-temp);
                    else
                        stk.push(temp);
                }
            }
        }
        //cout<<stk.top()<<endl;
        return stk.top();
    }

};